/*
 * PGN_Reader : A simple pgn reader for chess games.
 * Copyright (C) 2011 Laurent BERNABE
 * 
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
package com.gmail.bernabe.laurent.java_swing.pgn_reader.processing.piece.piece_allowed_moves;

import com.gmail.bernabe.laurent.java_swing.pgn_reader.processing.HalfMoveData;
import com.gmail.bernabe.laurent.java_swing.pgn_reader.processing.PlayingTape;
import com.gmail.bernabe.laurent.java_swing.pgn_reader.processing.move.PieceMovingDeltas;
import com.gmail.bernabe.laurent.java_swing.pgn_reader.processing.piece.PawnStatus;

public class PawnAllowedMoves extends AllowedMoves {

	@Override
	public PieceMovingDeltas[] getAllowedMoves(int playerTurn,
			HalfMoveData halfMoveData, PawnStatus[][] pawnStatusClone) {
		PieceMovingDeltas[] allowedDisplacements_FromMoveEndCell;
		int deltaY;
		if (playerTurn == PlayingTape.WHITE)
			deltaY = 1;
		else
			deltaY = -1;
		if (halfMoveData.isACapturingMove()) {
			allowedDisplacements_FromMoveEndCell = new PieceMovingDeltas[2];
			allowedDisplacements_FromMoveEndCell[0] = new PieceMovingDeltas(-1, -deltaY);
			allowedDisplacements_FromMoveEndCell[1] = new PieceMovingDeltas(+1, -deltaY);
		} else {
			if (pawnStatusClone[playerTurn][halfMoveData.getEndCell().cellColumn].hasEverPlayed){
				allowedDisplacements_FromMoveEndCell = new PieceMovingDeltas[1];
				allowedDisplacements_FromMoveEndCell[0] = new PieceMovingDeltas(0, -deltaY);
			}
			else {
				allowedDisplacements_FromMoveEndCell = new PieceMovingDeltas[2];
				allowedDisplacements_FromMoveEndCell[0] = new PieceMovingDeltas(0, -deltaY);
				allowedDisplacements_FromMoveEndCell[1] = new PieceMovingDeltas(0, -2*deltaY);
			}
		}
		return allowedDisplacements_FromMoveEndCell;
	}

}
